<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" href="keyword.css" type="text/css">
<script src="mylib.js" type="text/javascript"></script>
<script src="class.js" type="text/javascript"></script>
<script src="HightCode.js" type="text/javascript"></script>
</head>

<body>
<p>
  <input name="" type="button" value="行号显示/隐藏" onClick="toggle(getClass('td','num'));" style="margin:0px;">
 <div id=ss style="display:none;"> 
 <?php
/*fileName: 
 *internal version: 0001
 *version : 1.0.0 [programming] [official version]
 *author : HeShengyu
 *Date : 2014.07.21 
 *email: koolfer@163.com
 *end date:2014.08.23
 *http://www.cnblogs.com/ssnowy/
*/
/*
*文件中包类
 Clfn
 Clscandir
*/
//DEBUG_GRADE_ 的值越大越容易显示抛出信息
$baselibroot=str_replace('//','/',dirname(__FILE__).'/');
require_once $baselibroot.'globals.php';

define('DEBUG_GRADE',3);
//$nGrade数字越小越容易显示抛出信息示
function _debug($str,$nGrade=3){
    return $nGrade<DEBUG_GRADE ? $str : ""; 
}

class Clfn{
    public $root;
	public $httpdRoot;
	public $fileUrls;
    public function __construct($path=""){
		$this->root=Clfn::chSlashs($path);
		$this->fileUrls = array();	
	}
	/*
	//chSlashs
	//$path 一般传入 __FILE__
	//把反斜杠替换成正斜杠，把多个正斜杠替换成一个
	*/
	public static function chSlashs ($path=""){
        return preg_replace( 
				array('/\/{1,}/'), 
				array('/'       ),
					str_replace( 
					   '\\','/' , 
					   dirname($path).DIRECTORY_SEPARATOR 
					)   
			);
		 
	}
	public function __destruct(){
	}
	public function requireOnce($arrOrStr){
		if(is_array($arrOrStr)){
			foreach($arrOrStr as $v){
			    require_once($this->root.$v)  ;
			}	
			return $this;
		}
		if(is_dir($this->root.$arrOrStr)){
			$this->requireDirOnce($arrOrStr);
			return $this;		
		}
		if(!empty($arrOrStr)){
			require_once($this->root.$arrOrStr);
		}
		return $this;				
	}
	//$suffix 例如等于 "../../"."inc/"
	//通过路径包含php文件一次
	public   function requireDirOnce($suffix=''){	
	    $bool=function_exists('_debug');	
		$s=new clscandir($this->root.'/'.$suffix);
		$arr=$s->getCompleteFiles();	
		
		if($bool){
			foreach($arr as $v){
				if(preg_match("/\.php$/",$v) ){
			    echo _debug( _mkcstr("require_once('".$v."')</br>")->High('red',16)->Val() , 3 );			    }
			}	
		}
		foreach($arr as $v){
			if(preg_match("/\.php$/",$v) ){
			require_once($v) ;		
			}
		}		
	}
	//$grade为数字
	//例如：为0返回 I:/AppServ/www/_lovely/incInterface/
	//为1返回 I:/AppServ/www/_lovely/
	//为2返回 I:/AppServ/ww
	public function getWebRoot($grade=''){
		if($grade==''){
		    return $this->root;	
		}
		$frequencyExpression='{0,'.$grade.'}';
		if($grade==1){
		    $frequencyExpression='{1}';
		}
		$this->httpdRoot=preg_replace('/([^\/]{0,}\/)'.$frequencyExpression.'$/'
		        ,'',$this->root);	
		return $this->httpdRoot;
	}
	//TODO:把 I:\Appserv\www\a\b 变为
	//I:\Appserv\www\
	//getHttpdRoot("\a\b")
	public function getHttpdRoot($str=""){
		if($str==""){return "";}
		$sRet=str_replace($str,"",$this->root);
		$this->httpdRoot=$sRet;
	    return  $this->httpdRoot;	
	}
	//TODO:例如把 I:\Appserv\www\a.php替换成http://localhost:90/a.php
	//$server_url 为 http://localhost:90/
	//$this->httpdRoot  为 I:\Appserv\www\
	//用filePathToUrl这个方法前一定要先使用getHttpdRoot方法以得到
	//httpdRoot httpdRoot例如为 I:\Appserv\www\
	public function filePathToUrl($filePath=""){	
		if($filePath==""){return "";}
	    $server_url=Clfn::iGetServerUrl();
		$ret = str_replace(
		$httproot,$server_url,$filePath);
		$this->fileUrls[]=$ret;
		return $ret;
	}
	
	//internal 使用  
	public static function iGetServerUrl(){
        return 	"http://".$_SERVER[SERVER_NAME]
		.":".$_SERVER[SERVER_PORT]."/";
	}
	
 	
}

class Clscandir{
    public $path;
	public $completeFiles ;
	public $completeDirs ;
	public $files;
	public $dirs ;
	public $filesDirs ;
	public $completeFilesDirs ;
	//把文件转化为文件所在目录字串
	public static function fileToDirname($path){
	    if( is_file($path) ){
		    return dirname($path);	
		} 
		return $path;
	}
    public function  __construct($path="I:/_phplib/",$sortingOrder=0){
		$path = Clscandir::fileToDirname($path);
		$this->path = $path ;
		$this->scandir($path , $sortingOrder);
		$this->getCompleteFilesDirs();
		$this->getCompleteDirs();
		return $this->filesDirs;
	}
	//  第一步
	public function  scandir($path='',$sortingOrder=0){
		if(empty($path)){
		    $path=$this->path;	
		}
		$this->filesDirs=scandir ( $path , $sortingOrder ) ;  
		return $this->filesDirs;       
		//sort()升序  rsort()降序 ;
	}
	
	//得到完整路径的目录和文件
	public function getCompleteFilesDirs(){
		if(count($this->completeFilesDirs)==0){
			foreach($this->filesDirs as $k => $v ){
				$this->completeFilesDirs[] = self::formatPath($this->path."/".$v);   	
			}
		}
		return $this->completeFilesDirs;
		
	} 
	//得到完整的目录名和文件名  
	public function getCompleteDirs(){

		if(count($this->completeDirs)==0){
			foreach($this->completeFilesDirs as $k=>$v){			
				if(is_dir($v)){
					$this->completeDirs[]=$v;
				}else{
					$this->completeFiles[]=$v;	
				}	
			}
		}
		return $this->completeDirs;
		
	}
	public function getCompleteFiles(){
		return $this->completeFiles;
	}	

	public static function formatPath($str){		
	    return preg_replace (     '/\/{1,}/' , '/' ,
	           str_replace ( '\\' , '/' , $str )   ) ;	
    }
	

	public static function toHttpUrl($arr,
	$middle_path="/_doll/_ae/"){
		$severpath="http://".$_SERVER['SERVER_NAME']
		.":".$_SERVER['SERVER_PORT']
		.$middle_path;
        $retarr=array();
		foreach($arr as $k=>$v){
			 $v=preg_replace(
	  "/[\d\D]*\/([a-zA-Z0-9_\.\-\[\]\(\)]*\.(?:flv|f4v|mp[4]|mkv))$/"
       ,$severpath."\\1",$v);
	       if(!preg_match("/^[a-zA-Z]\:/",$v))
		   {
			   $retarr[$k]=Clscandir::replacePoundsign($v); 	
		   }	
		}
		return $retarr;		
	}
	public static function replacePoundsign($str){
        $str=iconv('GB2312','UTF-8', $str)  ;
	    $str= preg_replace("/#/","%23",$str);
		return $str;
	}	
	public  function getHttpUrls($wwwPath,$arr=''){
		
		if( empty($arr) ){
			$arr = $this->getCompleteFiles() ;
		}
		
		$retarr=array();
		foreach($arr as $k=>$v){
			$retarr[]=self::filetourl($wwwPath,$v);
		}
		return $retarr;
	}
	public static function filetourl($wwwPath,$filename,$s=''){
		
		$server_url="http:".$s."//".$_SERVER['SERVER_NAME'].":".$_SERVER['SERVER_PORT']."/";
		return str_replace(array($wwwPath,"#"),array($server_url,"%23"),$filename);
		
	}
}

function _mkcstr($str){
   return new Clstring($str);	
}
class Clstring{
	public $string;
    public function __construct($str){
		$this->string=$str;
	}
	public function Val(){
		return $this->string;
		}
	public function High($color="#f90",$size=20){
		$this->string=
		 '<span style="color:'.$color
		.';font-size:'
		.$size.'px;">'.$this->string.'</span>';
		return $this;
	}
	public function Fast($color="#f90",$size=20){
	    $this->High($color,$size)	;
		return $this->Val();
	}
	public function __destruct(){
		$this->string=NULL;
	}
	public function Add($str){
	   	$this->string.=$str;
		return $this;
	}	
}
?>
 </div> 
 
<script>
var d=new Date()
var sTime=d.getTime();
var ss=document.getElementById('ss').innerHTML;		
document.write(HightCode.arr2TableStr(ss))

var d2=new Date()
var eTime=d2.getTime();
console.log('js代码运行毫秒数：'+(eTime-sTime) )
_mkDiv('position:absolute; margin:0px;right:0px; top:0px;font-size:12px;color:blue;','js代码运行毫秒数：'+(eTime-sTime));
</script>
</body>
</html>